package com.site.wisdom_construction.controller.iotModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.responseEntity.TwoDataResult;
import com.site.wisdom_construction.service.iotModule.FoundationAxialService;
import com.site.wisdom_construction.statisticsResult.FoundationAxialName;
import com.site.wisdom_construction.util.verification.NoToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/2/20
 * @Description
 */
@Api(tags = "基坑轴力监测")
@RestController
@RequestMapping("FoundationAxial")
@CrossOrigin
public class FoundationAxialController {
    @Autowired
    private FoundationAxialService foundationAxialService;


    @ApiOperation(value = "增加基坑轴力监测", notes = "测试数据:{\n" +
            "\"projectId\":\"66\",\n" +
            "\"name\":\"张三监测点\",\n" +
            "\"localReading\":3.225,\n" +
            "\"axialValue\":4.222,\n" +
            "\"variable\":9.999,\n" +
            "\"cumulativeVariable\":15435.66,\n" +
            "\"upTime\":\"2022-03-22 19:55:33\"\n" +
            "}")
    @PostMapping("/insertFoundationAxial")
    public JsonResult insertFoundationAxial(@RequestBody Map map) {
        JsonResult jsonResult = new JsonResult();
        int i = foundationAxialService.insertFoundationAxial(map);
        if (i == 1) {
            jsonResult.setCode(200);
            jsonResult.setMessage("增加成功");
            return jsonResult;
        } else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("增加失败");
            return jsonResult;
        }

    }

    @ApiOperation(value = "统计数据", notes = "测试数据:")
    @PostMapping("/countFoundationAxial")
    public TwoDataResult countFoundationAxial(@RequestBody Map map) {
        TwoDataResult twoDataResult = new TwoDataResult();
        List<FoundationAxialName> foundationAxialNames = foundationAxialService.countFoundationAxialByName(map);
        System.out.println(foundationAxialNames);
        for (int i = 0; i < foundationAxialNames.size(); i++) {
            String name = foundationAxialNames.get(i).getName();
            foundationAxialNames.get(i).setData(foundationAxialService.findFoundationAxialByName(name));
        }
        twoDataResult.setDataOne(foundationAxialNames);
        twoDataResult.setDataTwo(foundationAxialService.countFoundationAxialByUpTime(map));
        return twoDataResult;
    }

    @ApiOperation(value = "查询所有数据", notes = "测试数据:")
    @PostMapping("/findFoundationAxial")
    public OneDataResult findFoundationAxial(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(foundationAxialService.findFoundationAxial(map));
        return oneDataResult;
    }

    @ApiOperation(value = "根据名称查询最新数据", notes = "测试数据:")
    @PostMapping("/findFoundationAxialByNameNew")
    public OneDataResult findFoundationAxialByNameNew(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(foundationAxialService.findFoundationAxialByNameNew(map));
        return oneDataResult;
    }


    @ApiOperation(value = "模糊分页查询基坑轴力", notes = "测试数据:{\n" +
            "\t\"pageNo\": 1,\n" +
            "\t\"pageSize\": 10,\n" +
            "\t\"name\": \"\"\n" +
            "}")
    @PostMapping("/findFoundationAxialByPage")
    public Page findFoundationAxialByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(foundationAxialService.Total(map));
        page.setItems(foundationAxialService.findFoundationAxialByPage(map));
        return page;
    }
}
